<!--采购公告-->

<template>
  <div style="display: flex;  flex-direction: column;">
    <div style="display: flex; max-height: 20px">
      <h5 style="margin-left: 30px">采购方式</h5>
      <el-select v-model="procurementMethod" placeholder="请选择" style="margin-top: -5px;margin-left: 10px; width: 120px">
        <el-option :key="''" :label="'全部'" :value="''"></el-option>
        <el-option :key="'磋商'" :label="'磋商'" :value="'磋商'"></el-option>
        <el-option :key="'委托'" :label="'委托'" :value="'委托'"></el-option>
        <el-option :key="'竞价'" :label="'竞价'" :value="'竞价'"></el-option>
      </el-select>
      <h5 style="margin-left: 30px">项目编号</h5>
      <el-input style="margin-top: -5px; width:120px; margin-left: 10px" placeholder="请输入项目编号" v-model="projectNumber"></el-input>
      <h5 style="margin-left: 30px">项目名称</h5>
      <el-input style="margin-top: -5px; width:120px; margin-left: 10px" placeholder="请输入项目名称" v-model="projectName" ></el-input>
      <el-button type="primary" style="margin-top: -5px; margin-left: 30px" icon="el-icon-search"  @click="init">查询</el-button>
      <el-button type="warning" style="margin-top: -5px; margin-left: 10px" icon="el-icon-refresh"  @click="reset">重置</el-button>
    </div>
    <div style="display: flex; margin-top: 20px">
      <el-table :data="tableData" style="width: 100%" height="500">
        <el-table-column fixed label="序号" width="45">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column fixed prop="announcementName" label="公告名称"></el-table-column>
        <el-table-column fixed prop="projectNumber" label="项目编号" width="100"></el-table-column>
        <el-table-column fixed prop="projectName" label="项目名称" width="120"></el-table-column>
        <el-table-column prop="quantity" label="数量" width="45"></el-table-column>
        <el-table-column prop="status" label="状态" width="70">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === 0" type="danger" effect="circle">待进行</el-tag>
            <el-tag v-else-if="scope.row.status === 1" type="warning" effect="circle">待公告</el-tag>
            <el-tag v-else-if="scope.row.status === 2" type="success" effect="circle">已公告</el-tag>
            <el-tag v-else-if="scope.row.status >= 3" type="info" effect="circle">已结束</el-tag>
            <span v-else>未知</span>
          </template>
        </el-table-column>
        <el-table-column prop="procurementType" label="采购类型" width="70">
          <template slot-scope="scope">
            <span v-if="scope.row.procurementType === '公开采购'">公开采购</span>
            <span v-else-if="scope.row.procurementType === '单一来源'">单一来源</span>
            <span v-else>未知</span>
          </template>
        </el-table-column>
        <el-table-column prop="announDate" label="公告时间" width="170"></el-table-column>
        <el-table-column prop="enlistsDepart" label="报名单位" width="45">
          <template slot-scope="scope">
            <span class="clickable" @click="handleEnlistDepart(scope.row)">{{ scope.row.enlistsDepart }}家</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="300">
          <template slot-scope="scope">
            <el-button type="success" @click="handleLook(scope.row)">查看</el-button>
            <el-button type="warning" @click="handleEdit(scope.row)">编辑</el-button>
            <span style="margin-left: 10px">
              <el-button v-if="scope.row.enlistsDepart < 3 && scope.row.status < 3" type="info" @click="handleOnly(scope.row)">转单-来源</el-button>
              <el-button v-else type="primary" ref="signInButton" @click="signIn(scope.row)">签到表</el-button>
            </span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="padding: 10px 0;margin-left: 800px">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[10, 15, 20, 30]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
<!--    查看公告-->
    <el-dialog :visible.sync="dialogFilePublicVisible"
               :custom-class="'slide-right-dialog'"
    >
      <div class="dialog-content">
        <div style="border: 2px solid #409EFF; border-radius: 5px; padding: 20px; background-color: #f2f7fc; margin-bottom: 20px;">
          <el-descriptions :title="announForm.title" style="display: inline-block;margin-top: -100px" column="4" size="mini">
            <el-descriptions-item label="采购方式">{{announForm.procurementMethod}}</el-descriptions-item>
            <el-descriptions-item label="项目预算（万元）">{{ announForm.budget }}</el-descriptions-item>
          </el-descriptions>
        </div>
        <div class="dialog-title"><i class="el-icon-d-arrow-right"></i>查看公告</div>
        <el-card>
        <el-form :model="announForm" :rules="rules" :ref="announForm" label-width="100px" class="demo-ruleForm custom-form" style="margin-top: 20px">
          <el-form-item label="公告名称" prop="announcementName">
            <el-input v-model="announForm.announcementName" readonly></el-input>
          </el-form-item>
          <el-form-item label="响应文件递交截止时间" prop="deadline">
            <el-input v-model="announForm.deadline" readonly></el-input>
          </el-form-item>
          <el-form-item label="磋商地点" prop="pofc">
            <el-input v-model="announForm.pofc" readonly></el-input>
          </el-form-item>
          <el-form-item label="递交响应文件方法" prop="putMethod">
            <el-input v-model="announForm.putMethod" readonly></el-input>
          </el-form-item>
          <el-form-item label="公告时间" prop="projectName">
            <div class="block">
              <el-input v-model="announForm.announDate" readonly></el-input>
            </div>
          </el-form-item>
          <el-form-item label="公告附件" prop="announcementFileUrl">
            <a :href="announForm.announcementFileUrl" target="_blank" v-if="announForm.announcementFileUrl">公告附件</a>
          </el-form-item>
          <el-form-item label="公告内容" prop="announcementText">
            <el-input type="textarea" v-model="announForm.announcementText" readonly></el-input>
          </el-form-item>
          <el-form-item>
            <el-button @click="dialogFilePublicVisible = false">关闭</el-button>
          </el-form-item>
        </el-form>
        </el-card>
      </div>
    </el-dialog>
<!--    编辑公告-->
    <el-dialog :visible.sync="dialogEditVisible"
               :custom-class="'slide-right-dialog'"
    >
      <div class="dialog-content">
        <div style="border: 2px solid #409EFF; border-radius: 5px; padding: 20px; background-color: #f2f7fc; margin-bottom: 20px;">
          <el-descriptions :title="editForm.title" style="display: inline-block;margin-top: -100px" column="4" size="mini">
            <el-descriptions-item label="采购方式">{{editForm.procurementMethod}}</el-descriptions-item>
            <el-descriptions-item label="项目预算（万元）">{{ editForm.budget }}</el-descriptions-item>
          </el-descriptions>
        </div>
        <div class="dialog-title"><i class="el-icon-d-arrow-right"></i>编辑公告</div>
        <el-card>
        <el-form :model="editForm" :ref="editForm" label-width="100px" style="margin-top: 20px">
          <el-form-item label="公告名称" prop="announcementName">
            <el-input v-model="editForm.announcementName" readonly></el-input>
          </el-form-item>
          <el-form-item label="响应文件递交截止时间" prop="deadline">
            <el-date-picker
                v-model="editForm.deadline"
                type="datetime"
                placeholder="选择日期时间"
                :picker-options="pickerOptionsDead">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="递交响应文件方法" prop="putMethod">
            <el-input v-model="editForm.putMethod"></el-input>
          </el-form-item>
          <el-form-item label="磋商地点" prop="pofc">
            <el-input v-model="editForm.pofc"></el-input>
          </el-form-item>
          <el-form-item label="公告时间" prop="projectName">
            <div class="block">
              <el-date-picker
                  v-model="editForm.dateRange"
                  type="daterange"
                  align="right"
                  unlink-panels
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  :picker-options="pickerOptions">
              </el-date-picker>
            </div>
          </el-form-item>
          <el-form-item label="公告附件" prop="announcementFileUrl">
            <el-upload
                :action="'http://' + serverIp() + ':8081/jdyfy/file/upload'"
                :show-file-list="true"
                :on-success="handleAnnounFile"
                :on-error="handleAnnounFileError">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传不超过50mb的文件</div>
            </el-upload>
          </el-form-item>
          <el-form-item label="公告内容" prop="announcementText">
            <el-input type="textarea" v-model="editForm.announcementText"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="saveEdit">确定</el-button>
            <el-button @click="dialogEditVisible = false">取 消</el-button>
          </el-form-item>
        </el-form>
        </el-card>
      </div>
    </el-dialog>
<!--    报名单位-->
    <el-dialog :visible.sync="dialogEnlistDepartVisible"
               :custom-class="'slide-right-dialog'"
    >
      <div class="dialog-content">
        <div style="border: 2px solid #409EFF; border-radius: 5px; padding: 20px; background-color: #f2f7fc; margin-bottom: 20px;">
          <el-descriptions :title="enlistsForm.title" style="display: inline-block;margin-top: -100px" column="4" size="mini">
            <el-descriptions-item label="采购方式">{{enlistsForm.procurementMethod}}</el-descriptions-item>
            <el-descriptions-item label="项目预算（万元）">{{ enlistsForm.budget }}</el-descriptions-item>
          </el-descriptions>
        </div>
        <div class="dialog-title"><i class="el-icon-d-arrow-right"></i>报名单位</div>
        <el-form :model="enlistsForm" :rules="rules" :ref="enlistsForm" label-width="100px" class="demo-ruleForm custom-form" style="margin-top: 30px">
          <el-form-item label="报名单位" prop="enlistsDepart">
            <el-tag>{{enlistsForm.enlistsDepart}}家</el-tag>
            <br>
            <template v-if="enlistsForm.enlistsDepart < 3">
              <span class="error-message">报名单位不足3家</span>
            </template>
            <template v-else>
              <span class="valid-message">共3家</span>
            </template>
          </el-form-item>
          <el-collapse v-model="activeNames">
            <!-- 第一层 -->
            <el-collapse-item title="" name="1">
              <template slot="title">
                <span class="custom-title">1. 单位名称 {{ enlistsForm.departmentName1 }}</span>
              </template>
              <el-form-item label="联系人" prop="companyPerson">
                <el-input v-model="enlistsForm.companyPerson1"></el-input>
              </el-form-item>
              <el-form-item label="联系电话" prop="companyPhone">
                <el-input v-model="enlistsForm.companyPhone1"></el-input>
              </el-form-item>
              <el-form-item label="报名邮箱" prop="companyEmail">
                <el-input v-model="enlistsForm.companyEmail1"></el-input>
              </el-form-item>
              <el-form-item label="报名时间" prop="enlistsTime">
                <el-input v-model="enlistsForm.enlistsTime1"></el-input>
              </el-form-item>
              <el-form-item label="法人代表授权书" prop="alrFileUrl">
                <div>
                  <!-- 使用动态绑定来显示图片 -->
                  <img :src="enlistsForm.alrFileUrl1" alt="图片" v-if="enlistsForm.alrFileUrl1" width="200" height="250" />
                  <!-- 如果没有图片，显示提示 -->
                  <span v-else>无</span>
                </div>
              </el-form-item>
            </el-collapse-item>

            <!-- 第二层 -->
            <el-collapse-item title="" name="2">
              <template slot="title">
                <span class="custom-title">2. 单位名称 {{ enlistsForm.departmentName2 }}</span>
              </template>
              <el-form-item label="联系人" prop="companyPerson">
                <el-input v-model="enlistsForm.companyPerson2"></el-input>
              </el-form-item>
              <el-form-item label="联系电话" prop="companyPhone">
                <el-input v-model="enlistsForm.companyPhone2"></el-input>
              </el-form-item>
              <el-form-item label="报名邮箱" prop="companyEmail">
                <el-input v-model="enlistsForm.companyEmail2"></el-input>
              </el-form-item>
              <el-form-item label="报名时间" prop="enlistsTime">
                <el-input v-model="enlistsForm.enlistsTime2"></el-input>
              </el-form-item>
              <el-form-item label="法人代表授权书" prop="alrFileUrl">
                <div>
                  <!-- 使用动态绑定来显示图片 -->
                  <img :src="enlistsForm.alrFileUrl2" alt="图片" v-if="enlistsForm.alrFileUrl2" width="200" height="250" />
                  <!-- 如果没有图片，显示提示 -->
                  <span v-else>无</span>
                </div>
              </el-form-item>
            </el-collapse-item>

            <!-- 第三层 -->
            <el-collapse-item title="" name="3">
              <template slot="title">
                <span class="custom-title">3. 单位名称 {{ enlistsForm.departmentName3 }}</span>
              </template>
              <el-form-item label="联系人" prop="companyPerson">
                <el-input v-model="enlistsForm.companyPerson3"></el-input>
              </el-form-item>
              <el-form-item label="联系电话" prop="companyPhone">
                <el-input v-model="enlistsForm.companyPhone3"></el-input>
              </el-form-item>
              <el-form-item label="报名邮箱" prop="companyEmail">
                <el-input v-model="enlistsForm.companyEmail3"></el-input>
              </el-form-item>
              <el-form-item label="报名时间" prop="enlistsTime">
                <el-input v-model="enlistsForm.enlistsTime3"></el-input>
              </el-form-item>
              <el-form-item label="法人代表授权书" prop="alrFileUrl">
                <div>
                  <!-- 使用动态绑定来显示图片 -->
                  <img :src="enlistsForm.alrFileUrl3" alt="图片" v-if="enlistsForm.alrFileUrl3" width="200" height="250" />
                  <!-- 如果没有图片，显示提示 -->
                  <span v-else>无</span>
                </div>
              </el-form-item>
            </el-collapse-item>
          </el-collapse>
          <el-form-item style="margin-top: 20px">
              <el-button type="info" style="margin-top: 30px; margin-left: -100px" @click="dialogEnlistDepartVisible = false">取 消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
<!--    签到表-->
    <el-dialog :title="signInForm.title" :visible.sync="dialogSignInVisible">
      <div class="dialog-content">
        <div style="margin-bottom: 20px; text-align: center"><span>(招标项目编号:{{signInForm.projectNumber}})</span></div>
        <el-table :data="signInData" border>
          <el-table-column label="序号">
            <template slot-scope="scope">
              {{ scope.$index + 1 }} <!-- 使用 $index 来显示序号 -->
            </template>
          </el-table-column>
          <el-table-column property="departmentName" label="单位名称"></el-table-column>
          <el-table-column property="companyPerson" label="联系人"></el-table-column>
          <el-table-column property="companyPhone" label="联系电话"></el-table-column>
          <el-table-column property="enlistsTime" label="签到时间"></el-table-column>
        </el-table>
        <div style="margin-top: 20px; text-align: center">
          <el-button type="primary" @click="exp" style="margin-bottom: 30px">导出</el-button>
        </div>
      </div>
    </el-dialog>
<!--    转单一来源-->
    <el-dialog :visible.sync="dialogOnlyVisible"
               :custom-class="'slide-right-dialog'"
    >
      <div class="dialog-content">
        <!-- 右上角红色斜角提示 -->
        <div class="notification-badge">转单一来源</div>
        <div style="border: 2px solid #409EFF; border-radius: 5px; padding: 20px; background-color: #f2f7fc; margin-bottom: 20px;">
          <el-descriptions :title="onlyForm.title" style="display: inline-block;margin-top: -100px" column="4" size="mini">
            <el-descriptions-item label="采购方式">{{onlyForm.procurementMethod}}</el-descriptions-item>
            <el-descriptions-item label="项目预算（万元）">{{ onlyForm.budget }}</el-descriptions-item>
          </el-descriptions>
        </div>
        <div class="dialog-title"><i class="el-icon-d-arrow-right"></i>编辑公告</div>
        <el-card>
          <el-form :model="onlyForm" :rules="rules" :ref="onlyForm" label-width="100px" class="demo-ruleForm custom-form" style="margin-top: 20px">
            <el-form-item label="公告名称" prop="announcementName">
              <el-input v-model="onlyForm.announcementName"></el-input>
            </el-form-item>
            <el-form-item label="响应文件递交截止时间" prop="deadline">
              <el-date-picker
                  v-model="onlyForm.deadline"
                  type="datetime"
                  placeholder="选择日期时间"
                  :picker-options="pickerOptionsDead">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="递交响应文件方法" prop="putMethod" readonly>
              <el-input v-model="onlyForm.putMethod"></el-input>
            </el-form-item>
            <el-form-item label="磋商地点" prop="pofc">
              <el-input v-model="onlyForm.pofc"></el-input>
            </el-form-item>
            <el-form-item label="公告时间" prop="projectName">
              <div class="block">
                <el-date-picker
                    v-model="onlyForm.dateRange"
                    type="daterange"
                    align="right"
                    unlink-panels
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :picker-options="pickerOptions">
                </el-date-picker>
              </div>
            </el-form-item>
            <el-form-item label="公告附件" prop="announcementFileUrl">
              <a :href="onlyForm.announcementFileUrl" target="_blank" v-if="onlyForm.announcementFileUrl">公告附件</a>
            </el-form-item>
            <el-form-item label="公告内容" prop="announcementText">
              <el-input type="textarea" v-model="onlyForm.announcementText"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="saveOnly">确定转单一来源</el-button>
              <el-button @click="dialogOnlyVisible = false">取 消</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {addNotification, addProject, getProjectPageByStatusSpace} from '@/api/project.js'
import {
  addAnnouncement,
  getAnnouncementByName,
  getAnnouncementsByProjectNumbers,
  getEnlistDepartmentCount
} from "@/api/announcement";
import {getDepartByDepartName} from "@/api/department";
import * as XLSX from 'xlsx';
import {serverIp} from "../../../../public/config.js";

export default {
  name: "Announcement",
  data() {
    return {
      tableData: [],
      signInData:[],
      procurementMethod:'',
      projectNumber: "",
      projectName: "",
      pageNum: 1,
      total: 0,
      pageSize: 10,
      dialogFilePublicVisible: false,
      dialogEditVisible: false,
      dialogEnlistDepartVisible: false,
      dialogSignInVisible: false,
      dialogOnlyVisible: false,
      updataAnnoStatus: {},
      activeNames: [], // 初始展开第一个折叠层
      pickerOptions: {
        shortcuts: [{
          text: '最近三天',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            end.setTime(end.getTime() + 3600 * 1000 * 24 * 3);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      pickerOptionsDead:{
        shortcuts: [{
          text: '三天后',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() + 3600 * 1000 * 24 * 3);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周后',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },
      announForm: {
        dateRange: [],
        pofc:'西安市（某某医院行政院区招采办会议室）',
      },
      enlistsForm: {},
      signInForm: {},
      onlyForm: {},
      updateForm: {},
      editForm: {},
      notiForm: {},
      form: {
        projectNumber: '',
        projectName: '',
        quantity: 1,//数量
        status: 2,
        procurementMethod: '',//采购方式
        procurementType: '',//采购类型
        applicant: '1',//申请人
      },
    }
  },
  created() {
    this.init();
  },
  methods: {
    serverIp() {
      return serverIp
    },
    init() { //初始化页面
      getProjectPageByStatusSpace(this.pageNum, this.pageSize,this.projectNumber,this.projectName,this.procurementMethod,1,2)
          .then(res => {
            //根据项目名称查询公告信息
            const projects = res.records;
            const projectNumbers = projects.map(project => project.projectNumber);
            // 根据项目编号集合查询对应公告信息
            getAnnouncementsByProjectNumbers(projectNumbers).then(announcements => {

              const announcementNames = announcements.map(announcement => announcement.announcementName);
              getEnlistDepartmentCount(announcementNames).then(ad => {
                const countAnnouncements = ad.reduce((acc, curr) => {
                  const announcementName = curr.announcementName;
                  if (acc[announcementName]) {
                    acc[announcementName]++;
                  } else {
                    acc[announcementName] = 1;
                  }
                  return acc;
                }, {});

                // 将公告信息添加到每个项目中
                projects.forEach(project => {
                  const announcement = announcements.find(a => a.projectNumber === project.projectNumber);
                  const announcementName = announcement ? announcement.announcementName : "无公告";

                  // 添加公告名和数量到项目中
                  project.announcementName = announcementName;
                  project.enlistsDepart = countAnnouncements[announcementName] || 0;  // 默认为0，如果没有找到公告

                  // 添加公告的开始时间和结束时间
                  const startTime = announcement ? announcement.announcementStartTime : "无公告";
                  const endTime = announcement ? announcement.announcementEndTime : "无公告";
                  if (startTime && endTime) {
                    project.announDate =`${startTime} - ${endTime}`;
                  }
                });

                this.tableData = projects;
                this.total = res.total;

              })
            });
          })
    },
    handleSizeChange(val) { //改变页码
      this.pageSize = val;
      this.init();
    },
    handleCurrentChange(val) { //改变每页显示条数
      this.pageNum = val;
      this.init();
    },
    async handleLook(row) { // 处理查看
      console.log(row)
      await getAnnouncementByName(row.announcementName).then(res => {
        this.announForm = res
        const startTime = res.announcementStartTime
        const endTime = res.announcementEndTime
        this.announForm.announDate =`${startTime} - ${endTime}`
        this.announForm.title = `${row.projectName}（招标项目编号${row.projectNumber}）`
        this.announForm.budget = row.budget
        this.announForm.procurementMethod = row.procurementMethod
        this.announForm.putMethod = '通过‘某某电子招投标交易平台’线上递交'
        this.announForm.pofc='西安市(某某医院行政院区招采办会议室）'
      })
      this.dialogFilePublicVisible = true
    },
    handleAnnounFile(row){ //保存文件下载路径
      this.fileUrl = row
      this.$message.success('文件添加成功')
    },
    handleAnnounFileError(err, file, fileList) {
      // 上传失败的处理逻辑
      this.$message.error('文件上传失败，请重试');
    },
    async handleEdit(row){ //处理编辑
      getAnnouncementByName(row.announcementName).then(res => {
        this.editForm=row
        this.$set(this.editForm,"announcementId", res.announcementId)
        this.$set(this.editForm,"dateRange" , [res.announcementStartTime, res.announcementEndTime])
        this.$set(this.editForm,"deadline" , res.deadline)
        this.$set(this.editForm,"title", `${row.projectName}（招标项目编号${row.projectNumber}）`)
        this.$set(this.editForm,"announcementText" ,res.announcementText)
        this.$set(this.editForm,"announcementFileUrl",res.announcementFileUrl)
        this.$set(this.editForm,"putMethod", '通过‘某某一附院电子招投标交易平台’线上递交')
        this.$set(this.editForm,"pofc",'西安市(某某医院行政院区招采办会议室）')
      })
      this.dialogEditVisible = true
    },
    saveEdit() { //保存修改
      const dateStr = this.editForm.dateRange[0];
      const date = new Date(dateStr);
      const formattedDate = date.toISOString().slice(0, 10);
      const dateStr1 = this.editForm.dateRange[1];
      const date1 = new Date(dateStr1);
      const formattedDate1 = date1.toISOString().slice(0, 10);
      const dateStr2 = this.editForm.deadline;
      const date2 = new Date(dateStr2);
      const formattedDate2 = date2.toISOString().slice(0, 19).replace('T', ' ');
      this.editForm.announcementStartTime=formattedDate
      this.editForm.announcementEndTime=formattedDate1
      this.editForm.deadline=formattedDate2
      this.editForm.announcementFileUrl = this.fileUrl !== '' ? this.fileUrl : this.editForm.announcementFileUrl
      this.fileUrl = ''
      addAnnouncement(this.editForm).then(res => {
        if(res){
          this.$message.success('修改成功')
          this.dialogEditVisible = false
          this.init()
        }
      })
    },
    async handleOnly(row){ //处理转单一来源
      await getAnnouncementByName(row.announcementName).then(res => {
        console.log(res)
        this.onlyForm = res
        this.$set(this.onlyForm,"projectName", row.projectName)
        this.$set(this.onlyForm,"dateRange", [res.announcementStartTime, res.announcementEndTime])
        this.$set(this.onlyForm,"deadline",res.deadline)
        this.$set(this.onlyForm,"budget",row.budget)
        this.$set(this.onlyForm,"procurementMethod", row.procurementMethod)
        this.$set(this.onlyForm,"title", `${row.projectName}（招标项目编号${row.projectNumber}）`)
        this.$set(this.onlyForm,"announcementText", res.announcementText)
        this.$set(this.onlyForm,"announcementFileUrl", res.announcementFileUrl)
        this.$set(this.onlyForm,"putMethod", '通过‘某某一附院电子招投标交易平台’线上递交')
        this.$set(this.onlyForm,"pofc",'西安市(某某医院行政院区招采办会议室）')
      })
      this.dialogOnlyVisible = true
    },
    async saveOnly() { //确定转单一来源
      const dateStr = this.onlyForm.dateRange[0];
      const date = new Date(dateStr);
      const formattedDate = date.toISOString().slice(0, 10);
      const dateStr1 = this.onlyForm.dateRange[1];
      const date1 = new Date(dateStr1);
      const formattedDate1 = date1.toISOString().slice(0, 10);
      const dateStr2 = this.onlyForm.deadline;
      const date2 = new Date(dateStr2);
      const formattedDate2 = date2.toISOString().slice(0, 19).replace('T', ' ');
      this.onlyForm.announcementStartTime=formattedDate
      this.onlyForm.announcementEndTime=formattedDate1
      this.onlyForm.deadline=formattedDate2
      this.onlyForm.announcementFileUrl = this.fileUrl !== '' ? this.fileUrl : this.onlyForm.announcementFileUrl
      this.fileUrl = ''
      addAnnouncement(this.onlyForm).then(res => {
        if(res){
          this.$message.success('项目信息修改成功')
          this.dialogOnlyVisible = false
        }
      })
      this.updateForm.projectNumber = this.onlyForm.projectNumber
      this.updateForm.status = 3
      this.updateForm.annoStatus = 2
      await addProject(this.updateForm).then(res => {
        if(res){
          this.$message.success('转单一来源成功')
        }else {
          this.$message.error('转单一来源失败')
        }
      })
      // this.notiForm.type = '转单一来源提醒'
      // this.notiForm.message = `您好，您参加的${this.projectName}转为单一来源，请重新提交报名资料。`
      // this.notiForm.timestamp = this.functiongetCurrentDateTime()
      // this.notiForm.departmentName = this.departmentName
      // addNotification()
      this.init()
    },
    functiongetCurrentDateTime() {
      const now = new Date();
      const year = now.getFullYear();
      const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始，所以加 1const day = String(now.getDate()).padStart(2, '0');
      const hours = String(now.getHours()).padStart(2, '0');
      const minutes = String(now.getMinutes()).padStart(2, '0');
      const seconds = String(now.getSeconds()).padStart(2, '0');
      return`${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    },
    async handleEnlistDepart(row){ //处理报名单位
      this.enlistsForm = row
      this.enlistsForm.title = `${row.projectName}（招标项目编号${row.projectNumber}）`
      await getEnlistDepartmentCount([row.announcementName]).then(res => {
        if(res[0]){
          this.enlistsForm.departmentName1 = res[0].departmentName
          this.enlistsForm.enlistsTime1 = res[0].enlistsTime
          this.enlistsForm.alrFileUrl1 = res[0].alrFileUrl
          getDepartByDepartName(res[0].departmentName).then(res => {
            this.enlistsForm.companyPerson1 = res.contactPerson
            this.enlistsForm.companyPhone1 = res.contactPhone
            this.enlistsForm.companyEmail1 = res.contactEmail
          })
        }
        if(res[1]){
          this.enlistsForm.departmentName2 = res[1].departmentName
          this.enlistsForm.enlistsTime2 = res[1].enlistsTime
          this.enlistsForm.alrFileUrl2 = res[1].alrFileUrl
          getDepartByDepartName(res[1].departmentName).then(res => {
            this.enlistsForm.companyPerson2 = res.contactPerson
            this.enlistsForm.companyPhone2 = res.contactPhone
            this.enlistsForm.companyEmail2 = res.contactEmail
          })
        }
        if(res[2]){
          this.enlistsForm.departmentName3 = res[2].departmentName
          this.enlistsForm.enlistsTime3 = res[2].enlistsTime
          this.enlistsForm.alrFileUrl3 = res[2].alrFileUrl
          getDepartByDepartName(res[2].departmentName).then(res => {
            this.enlistsForm.companyPerson3 = res.contactPerson
            this.enlistsForm.companyPhone3 = res.contactPhone
            this.enlistsForm.companyEmail3 = res.contactEmail
          })
        }
      })
      this.dialogEnlistDepartVisible = true
    },
    async signIn(row){ //签到表
      await this.handleEnlistDepart(row)
      await this.handleEnlistDepart(row)
      this.signInForm.title = `${row.projectName}签到表`
      this.signInForm.projectNumber = row.projectNumber
      this.signInForm.projectName = row.projectName
      this.signInData = [
        {
          departmentName: row.departmentName1,
          companyPerson: row.companyPerson1,
          companyPhone: row.companyPhone1,
          enlistsTime: row.enlistsTime1,
        },
        {
          departmentName: row.departmentName2,
          companyPerson: row.companyPerson2,
          companyPhone: row.companyPhone2,
          enlistsTime: row.enlistsTime2,
        },
          {
            departmentName: row.departmentName3,
            companyPerson: row.companyPerson3,
            companyPhone: row.companyPhone3,
            enlistsTime: row.enlistsTime3,
          }
      ]
      this.dialogSignInVisible = true

    },
    exp() { // 导出签到表
      const headers = ['单位名称', '联系人', '联系电话', '签到时间'];  // 定义表头中文
      const data = this.signInData.map(row => ({
        '单位名称': row.departmentName,
        '联系人': row.companyPerson,
        '联系电话': row.companyPhone,
        '签到时间': row.enlistsTime
      }));
        const ws = XLSX.utils.json_to_sheet(data, { header: headers });  // 将 JSON 数据转换为工作表
        const wb = XLSX.utils.book_new();  // 创建一个新工作簿
        XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');  // 将工作表添加到工作簿中

        // 生成 Excel 文件并触发下载
        XLSX.writeFile(wb, `${this.signInForm.projectName}项目签到数据.xlsx`);
    },
    reset() { //重置按钮
      this.procurementMethod = ''
      this.projectNumber = "";
      this.projectName = "";
      this.init();
    },
  },

}
</script>

<style scoped>
>>> .slide-right-dialog {
  top: -115px;
  right: 0;
  margin: 0;
  position: absolute;
  height: 2000px;
  width: 600px;
  animation: slide-right 0.3s ease;
}
>>> .slide-right-dialog .el-dialog__title {
  font-size: 20px; /* 调整对话框正文内容的字体大小 */
}
@keyframes slide-right {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}
.error-message {
  color: red;
  font-size: 12px;
  margin-top: 5px;
}

.valid-message {
  color: green;
  font-size: 12px;
  margin-top: 5px;
}
/* 给折叠面板的标题部分加背景色 */
.el-collapse-item__header {
  background-color: #f5f5f5; /* 背景色 */
  padding-left: 20px; /* 向右靠一点 */
  font-weight: bold; /* 加粗字体 */
  color: #333; /* 字体颜色 */
}

/* 自定义标题样式，避免直接修改 el-collapse-item__header */
.custom-title {
  display: inline-block;
  padding-left: 10px; /* 调整标题的偏移 */
  font-size: 16px;
  color: #409EFF; /* 标题的颜色 */
}
>>> .el-dialog__header {
  text-align: center;
}
>>> .el-dialog__body {
  padding: 0;
}
.dialog-content {
  position: relative;
  padding-left: 30px;  /* 左侧空隙 */
  padding-right: 30px; /* 右侧空隙 */
}
.notification-badge {
  font-family: 华文行楷,serif;
  position: absolute;
  top: 20px;
  right: 50px;
  background-color: thistle;
  color: red;
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 18px;
  transform: rotate(20deg); /* 让提示文字倾斜 */
  transform-origin: center; /* 设置旋转的中心点 */
  box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.2); /* 给提示添加阴影 */
}
</style>